﻿<?php 
	require('../../Smarty/libs/Smarty.class.php');
	
	$smarty = new Smarty;

	$smarty->setTemplateDir('./smarty/templates/');
	$smarty->setCompileDir('./smarty/templates_c/');
	$smarty->setConfigDir('./smarty/configs/');
	$smarty->setCacheDir('./smarty/cache/');
?>
<?php
        include("./api/APIObject.php");
        include("./api/room_group_class.php");
        
        $destination = $_POST["destination"];
        $checkIn = $_POST["check-in"];
        $checkOut = $_POST["check-out"];
        $roomCount = $_POST["room_noumber"];
        
        $rooms[1] = $_POST["room1"];
        $rooms[2] = $_POST["room2"];
        $rooms[3] = $_POST["room3"];
        $rooms[4] = $_POST["room4"];
        $rooms[5] = $_POST["room5"];
        $rooms[6] = $_POST["room6"];
        $rooms[7] = $_POST["room7"];        
        $rooms[8] = $_POST["room8"];

        //Create a new APIObject instance
        $apiObject = new APIObject("55505","cbrzfta369qwyrm9t5b8y8kf","7",
                "en_US","USD");
        
        /* test zone */
        
        /*print_r(html_entity_decode($apiObject->GetHotelInformation("106347", "HOTEL_DETAILS")->GetPropertyDescription()));*/
            
        
        /* test zone */
        for($roomIndex=1; $roomIndex <= $roomCount; $roomIndex++){
            $roomTest = new RoomRequest(
                $rooms[$roomIndex]["adultsCount"],
                $rooms[$roomIndex]["childrenCount"],
            array(
                $rooms[$roomIndex]["children1"],
                $rooms[$roomIndex]["children2"],
                $rooms[$roomIndex]["children3"]
                ),
            NULL,NULL,NULL,NULL,NULL);
        }

        $roomGroup = new RoomGroup(array($roomTest));
        
        /*$roomAvail = $apiObject->GetRoomAvaiability(
                "191973", 
                "10/11/2012", 
                "10/13/2012", 
                "1", 
                NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
                $roomGroup->GetXMLRequest());*/
        $testData =$apiObject->GetHotelList($checkIn, $checkOut, "7",
        //$testData =$apiObject->GetHotelList(NULL, NULL, "10", 
       rawurlencode($destination), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, $roomGroup->GetXMLRequest(), NULL, NULL, NULL, NULL);
		
		//print_r($testData);
        
		$searchData = $smarty->createData();
        $hotelArray = array();
        for ($index = 0; $index < count($testData); $index++) 
        {
            $hotelArray[$index]["thumbnailUrl"] = $testData[$index]->GetThumbnailUrl();
            $hotelArray[$index]["hotelName"] = $testData[$index]->GetName();
            $hotelArray[$index]["shortDesc"] = $testData[$index]->GetShortDescription() ;
			$hotelArray[$index]["lRate"]=$testData[$index]->GetLowRate();
			$hotelArray[$index]["hRate"]=$testData[$index]->GetHighRate();
		
            $hotelId = $testData[$index]->GetHotelId();
            //print_r($testData[$index]->GetConfidenceRating());
            $hotelArray[$index]["rating"] = $testData[$index]->GetHotelRating();
            //print_r($testData[$index]->GetHotelRating());
            $hotelArray[$index]["propertyDetails"] = html_entity_decode($apiObject->GetHotelInformation($hotelId, "HOTEL_DETAILS")->GetPropertyDescription());
			$hotelArray[$index]["id"]=$index;
         
		    $roomTypes = $apiObject->GetHotelInformation($hotelId, "ROOM_TYPES");
            for($index2 = 0; $index2 < 2; $index2++)
            {
                $hotelArray[$index]["roomTypes"][$index2]["description"] = $roomTypes[$index2]->GetDescription() ;
            }
         
		    $hotelImages = $apiObject->GetHotelInformation($hotelId, "HOTEL_IMAGES");
			$hotelArray[$index]["nrOfPictures"]=count($hotelImages);

            for($index2 = 0; $index2 < count($hotelImages); $index2++)
            {
                $hotelArray[$index]["hotelImages"][$index2]["thumbUrl"] = $hotelImages[$index2]->GetThumbnailUrl();

            }
			
			for($index2=0;$index2<count($hotelImages);$index2++)
			{
				$hotelArray[$index]["hotelImages"][$index2]["url"]=$hotelImages[$index2]->GetUrl();
				$hotelArray[$index]["hotelImages"][$index2]["nr_picture"]=$index2;	
                                
                               // list($width, $height, $type, $attr) = getimagesize($hotelArray[$index]["hotelImages"][$index2]["url"]);
				//$ratio=$width/$height;
                                /*
				$ratio=$hotelImages[$index2]->GetWidth()/$hotelImages[$index2]->GetHeight();//the same dimensions for all pictures
				
				if($ratio<500/300)
					{
						$width_p="";
						$height_p='height="300px"';

					}	
					else
					{
						
						$width_p='width="500px"';
						$height_p='';
					}
                                        */
				if($index2==0)
					{
						$style="display:block;";
					}
				else
					{
						$style="display:none;";
					}
				
				/*$hotelArray[$index]["hotelImages"][$index2]["width_p"]=$width_p;
				$hotelArray[$index]["hotelImages"][$index2]["height_p"]=$height_p;*/
				$hotelArray[$index]["hotelImages"][$index2]["style"]=$style;
			}
           
        }
        $searchData->assign("hotelArray",$hotelArray);
        $smarty->display("hotelsList.tpl",$searchData);
        

?>